/*
 * @(#)EmployeeAction.java   08/12/29
 *
 *
 */



package net.learntechnology.examples.stripes;

//~--- non-JDK imports --------------------------------------------------------

import com.google.inject.Inject;

import net.learntechnology.examples.domain.Employee;
import net.learntechnology.examples.service.EmployeeService;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 *
 * @author nmaves
 */
@UrlBinding("/employee")
public class EmployeeAction extends BaseAction {
	private static final String EMPLOYEE_FORM = "/WEB-INF/jsp/employeeForm.jsp";
	private Employee            employee;
	@Inject
	private EmployeeService     employeeService;

	public Resolution cancel() {
		return new RedirectResolution(EmployeeListAction.class);
	}

	public Resolution delete() {
		employeeService.delete(employee.getId());

		return new RedirectResolution(EmployeeListAction.class);
	}

	public Resolution save() {
		employeeService.save(employee);

		return new RedirectResolution(EmployeeListAction.class);
	}

	@DefaultHandler
	public Resolution edit() {
		if (employee.getId() != null) {
			employee = employeeService.get(employee.getId());
		}

		return new ForwardResolution(EMPLOYEE_FORM);
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
}
